package cn.kgm.nio;

import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.StandardCharsets;

public class NioFileChanalWrite {

    private final static String nioUrl = "niofile/";

    public static void main(String[] args) throws Exception{
        String hello = "hello,kappi";
        FileOutputStream fileOutputStream = new FileOutputStream(nioUrl + "wdd.txt");
        FileChannel channel = fileOutputStream.getChannel();
        ByteBuffer buffer = ByteBuffer.allocate(1024);
        buffer.put(hello.getBytes(StandardCharsets.UTF_8));
        buffer.flip();
        channel.write(buffer);
        fileOutputStream.close();
    }
}
